package cn.iocoder.yudao.module.shop.info.convert;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.api.pay.bill.enums.BillTypeEnum;
import cn.iocoder.yudao.module.api.pay.order.dto.PayOrderCreateDTO;
import cn.iocoder.yudao.module.api.shop.info.dto.ShopInfoDTO;
import cn.iocoder.yudao.module.shop.info.dal.dataobject.ShopEnterOrderDO;
import cn.iocoder.yudao.module.shop.info.dal.dataobject.ShopEnterPackageDO;
import cn.iocoder.yudao.module.shop.info.vo.ShopEnterOrderRespVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.Map;

@Mapper
public interface ShopEnterOrderConvert {

    ShopEnterOrderConvert INSTANCE = Mappers.getMapper(ShopEnterOrderConvert.class);

    default PayOrderCreateDTO convert(ShopEnterPackageDO enterPackageDO, ShopEnterOrderDO shopEnterOrderDO) {
        PayOrderCreateDTO createReqDTO = new PayOrderCreateDTO();
        createReqDTO.setTradeNo(shopEnterOrderDO.getTradeNo());
        createReqDTO.setSubject(BillTypeEnum.PAY_SHOP.getName());
        String enterPackageName = String.format("¥%.2f/%s年", enterPackageDO.getPrice() / 100f, enterPackageDO.getYear());
        createReqDTO.setBody("商家入驻缴费，" + enterPackageName);
        // 订单相关字段
        createReqDTO.setPrice(enterPackageDO.getPrice());
        return createReqDTO;
    }

    List<ShopEnterOrderRespVO> convertList(List<ShopEnterOrderDO> list);

    ShopEnterOrderRespVO convert2(ShopEnterOrderDO bean);

    PageResult<ShopEnterOrderRespVO> convert(PageResult<ShopEnterOrderDO> page);

    default PageResult<ShopEnterOrderRespVO> convert(PageResult<ShopEnterOrderDO> page, Map<Long, ShopInfoDTO> shops) {
        List<ShopEnterOrderRespVO> list = convertList(page.getList());
        list.forEach(item -> item.setShop(shops.get(item.getShopId())));
        PageResult<ShopEnterOrderRespVO> result = convert(page);
        result.setList(list);
        return result;
    }

}
